package executor;

import org.junit.Test;

import java.util.concurrent.*;

public class Demo1 {
    ExecutorService exec = Executors.newSingleThreadExecutor();

    @Test
    public void demo() {

        //FutureTask

        //exec.submit(null);

        exec.execute(() -> {
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                System.out.println("----");
            }
        });
    }


    ArrayBlockingQueue arrayBlockingQueue = new ArrayBlockingQueue(1);

    @Test
    public void demo3() throws Exception {

        CountDownLatch a=new CountDownLatch(2);

      Thread d=new Thread(()->{

            try {
                System.out.println("take "+ Thread.currentThread().getName());
                arrayBlockingQueue.take();
                a.countDown();
            }catch (Exception e){
                System.out.println("线程结束 "+Thread.currentThread().getName());
                e.printStackTrace();
            }
        });

      d.start();


      Thread.sleep(1000);

        new Thread(()->{
            try {
                d.interrupt();
                System.out.println(d.isInterrupted());
                a.countDown();
            }catch (Exception e){
            }
        }).start();

        try {
            a.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //Thread t = new Thread()

    }

}
